home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / d86v322.zip / D07.DOC < prev    next >
Text File  |  1988-01-14  |  9KB  |  202 lines

  1. CHAPTER 7    FLOATING POINT DEBUGGING
  2.  
  3. If your machine has an 8087 or 80287 chip, D86 gives you the best
  4. facilities for debugging code for the chip (which I generically
  5. refer to as "the 87").
  6.  
  7. The display of the 87's state can be obtained by pressing the
  8. Ctrl-F key.  If you don't have an 87 in your system, you won't
  9. get the display.
  10.  
  11. You can also display floating point numbers displayed in 86
  12. memory, by using the FD, FQ, and FT specifiers described in
  13. Chapter 6.
  14.  
  15. In the displays of floating point numbers, both on the 87 stack
  16. and in 86 memory, I've taken great care to provide a display that
  17. is both readable and accurate.  I rejected the algorithms for
  18. display found in the popular reference books on the subject,
  19. because they failed for several classes of extreme values.
  20.  
  21.  
  22. The Floating Point Display Window
  23.  
  24. The floating point display you get with Ctrl-F contains the
  25. following components:
  26.  
  27. 1. The top 8 lines contain the contents of each floating point
  28.    register.  The registers are displayed as a stack, with ST(0)
  29.    on top, numbered with "0:".  The format of the display depends
  30.    on whether the number is a plain, normal number, or whether it
  31.    is one of the exotic, non-normal types the 87 supports.  I'll
  32.    briefly describe the exotic types at the end of this chapter.
  33.    The possible displays are:
  34.  
  35.    ----       (four hyphens), denoting a stack slot tagged empty.
  36.  
  37.    nnn        a decimal number, displayed in scientific notation
  38.               if necessary.
  39.  
  40.    Infinity   for an overflowed result.
  41.  
  42.    NaN        for Not a Number, followed by the hexadecimal codes
  43.               of the significand field of the NaN
  44.  
  45.    Den        for denormal, followed by the number of bits of
  46.               precision lost, followed by the value of the
  47.               number.
  48.  
  49.    Unn        for unnormal, followed by the number of bits of
  50.               precision lost, followed by the value of the
  51.               number.
  52.  
  53.    Pseudo 0   for a pseudo zero, followed by the contents of the
  54.               exponent field.
  55.  
  56. 2. English-language displays for the infinity, precision, and
  57.    rounding mode settings for the chip.
  58.                                                               7-2
  59.  
  60. 3. The value of the instruction pointer for the instruction that
  61.    caused the last floating-point exception.  If all exceptions
  62.    are masked this doesn't change.
  63.  
  64. 4. The address of the memory operand for the instruction that
  65.    caused the last floating-point exception.  If all exceptions
  66.    are masked this doesn't change either.
  67.  
  68. 5. The value of the Tag register, for registers 7 through 0.
  69.    These register numbers are NOT the same as the stack element
  70.    numbers-- they are rotated by the value of ST, given on the
  71.    next line.  The possible values for the Tag register fields
  72.    are:
  73.  
  74.    f   for finite non-zero number
  75.    z   for zero
  76.    i   for infinite number
  77.    -   for empty slot
  78.  
  79. 6. The value of the stack pointer ST.  The tag-register number
  80.    for ST(i) is ST plus i.
  81.  
  82. 7. A display of which 87 exceptions are masked; i.e., will not
  83.    cause interrupts.  If the exception is masked, its letter is
  84.    displayed.  If it is not masked (interrupt will occur), a
  85.    blank is displayed.  The letters are:
  86.  
  87.    p   for precision exception
  88.    u   for underflow exception
  89.    o   for overflow exception
  90.    z   for zero-divide exception
  91.    d   for denormal exception
  92.    i   for invalid operation exception
  93.  
  94. 8. A display of which masked exceptions have occurred since the
  95.    last time the status bits were cleared.  The exceptions have
  96.    the same letters as the masked display.
  97.  
  98. 9. A display of the 87 Condition Flags C3 through C0.  A
  99.    displaying character is shown if the flag is set; a blank is
  100.    shown if the flag is cleared.  The characters are:
  101.  
  102.    z  for C3  (corresponds to the Zero flag)
  103.    u  for C2  (set if a result is "unordered")
  104.    .  for C1
  105.    c  for C0  (corresponds to the Carry flag)
  106.  
  107. 10. Another display of C3 through C0, this time showing the
  108.    results of an FXAM instruction.  This display is always
  109.    present, even when FXAM is not the last flag-setting
  110.    instruction executed (in which case the display is
  111.    meaningless).
  112.                                                               7-3
  113.  
  114. Exotic Flavors of Floating Point Numbers
  115.  
  116. Some of the types of numbers possible in the floating point
  117. register display may seem a little strange to you if you haven't
  118. had much experience with the 87.  It's a bit beyond the scope of
  119. this manual to go into detail about them-- you should consult a
  120. book such as "The 80286 Architecture" by Steve Morse for a
  121. detailed discussion.  But here are brief descriptions to give you
  122. a bit of an idea of what's going on:
  123.  
  124. NaN (Not-a-Number) values are used to represent results that are
  125. totally different than any floating-point number that could be
  126. provided.  A specific NaN (with hex value C000 0000 0000 0000) is
  127. produced by the 87 whenever it can't cope with something, and the
  128. Invalid Operation exception is masked.  Other NaN values might be
  129. loaded by a program from 86 memory, to be interpreted in any way
  130. the program chooses.
  131.  
  132. For the rest of this discussion, let's introduce a little
  133. terminology.  Floating point numbers use a format that follows
  134. the same principle as scientific notation.  In scientific
  135. notation, one part of the number gives the significant digits of
  136. the number, always "normalized" to fall between 1 and 10. Another
  137. part of the number gives the magnitude of the number: the power
  138. of ten that you multiply the first part by, to get the true
  139. value.  For example, 2.34 * 10**2 is a normal, scientific
  140. notation for 234.  (It can be written in A86 as 2.34E2).  2.34 *
  141. 10**-2 is a normal scientific notation for 0.0234.  Note that
  142. 0.234 * 10**-1 is a non-normal representation for the same
  143. number: we have increased the size of the exponent from -2 to -1,
  144. but the significant part is less than 1 instead of being between
  145. 1 and 10.
  146.  
  147. In the 87 formats, everything is binary, with bits instead of
  148. digits.  There is a "significand" field, normalized whenever
  149. possible so that the most significant bit is 1 (the value is
  150. between 1 and 2).  There is the "exponent" field, giving the
  151. (positive or negative) power of two that you multiply the
  152. significand by, to get the true value.
  153.  
  154. Denormals are produced when the result of an operation is non-
  155. zero, but is so tiny that its exponent is a negative number too
  156. small to be represented in the 15-bit exponent field of an 87
  157. register.  There is a trick called "gradual underflow" that makes
  158. the best of the situation: the smallest possible exponent is
  159. given, together with leading zeroes in the significand to signal
  160. a further reduction in the exponent.  Each leading zero means
  161. there is one less bit with which to represent the significand.
  162.  
  163. You can see denormals in action by typing Ctrl-F to get the
  164. floating-point display, then typing the following commands to be
  165. executed immediately:
  166.  
  167.      FINIT
  168.      FLD 10.0
  169.      FLD 1.E-4931
  170.      FDIV 1
  171.                                                               7-4
  172.  
  173. The result of the division is a denormal because 10 ** -4932 has
  174. a power-of-two exponent too small to be represented in the 15-bit
  175. exponent field of the 87 register.  The display indicates that 2
  176. bits of precision have been lost-- two leading zeroes have been
  177. forced into the significand field of the number.
  178.  
  179. Now press the F3 key to divide the number by another 10.  Now 5
  180. bits of precision have been lost.  If you keep pressing the F3
  181. key, you get more and more bits of precision lost.  The loss in
  182. accuracy shows up in the number displayed.  Eventually, all bits
  183. are lost, and the number collapses to zero.
  184.  
  185. What happens when we multiply a denormal number by 10, instead of
  186. dividing it by 10?  The number becomes big enough to no longer
  187. require the denormalization; but there's no way to recover the
  188. bits of precision that have been lost.  To signal that bits have
  189. been lost, the 87 retains the leading zeroes in the significand.
  190. Numbers containing such zeroes without